package com.example.baserecyclerviewadapterdemo.adapter;

import com.chad.library.adapter.base.BaseSectionQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.baserecyclerviewadapterdemo.R;
import com.example.baserecyclerviewadapterdemo.entity.MySection;
import com.example.baserecyclerviewadapterdemo.entity.Video;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class SectionQuickAdapter extends BaseSectionQuickAdapter<MySection, BaseViewHolder> {
    public SectionQuickAdapter(int sectionHeadResId, int layoutResId, @Nullable List<MySection> data) {
        super(sectionHeadResId, layoutResId, data);
        setNormalLayout(layoutResId);
        addChildClickViewIds(R.id.more);
    }

    @Override
    protected void convertHeader(@NotNull BaseViewHolder holder, @NotNull MySection mySection) {
        if (mySection.getObject() instanceof String) {
            holder.setText(R.id.header,mySection.getObject().toString());
        }
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, MySection mySection) {
        Video video = (Video) mySection.getObject();
        switch (holder.getLayoutPosition() % 2) {
            case 0:
                holder.setImageResource(R.id.iv,R.mipmap.animation_img1);
                break;
            case 1:
                holder.setImageResource(R.id.iv,R.mipmap.animation_img2);
                break;
            default:
                break;
        }
        holder.setText(R.id.tv,video.getName());
    }
}
